package com.niit.house.tgq.price;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;



public class PriceMapper extends Mapper<Object, Text, Text, PriceWritable> {

    @Override
    protected void map(Object key, Text value, Context context) throws IOException, InterruptedException {
        String[] record = value.toString().split(",");
        int isLift = 0;
        try {
            String district = record[1]; // 房屋所属市辖区在第1个字段
            String ownership = record[13]; // 交易权属态在第13个字段
            int price = Integer.parseInt(record[15]);


            context.write(new Text(district), new PriceWritable(ownership, price));
        } catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException e) {
            // 忽略解析失败的数据行
        }
    }
}